﻿using GalaSoft.MvvmLight.Messaging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Forms;
using WPF_MVVM_PathSearchUtil.ViewModels.commom;
using WPF_MVVM_PathSearchUtil.ViewModels.common;
using WPF_MVVM_PathSearchUtil.Views;
using static WPF_MVVM_PathSearchUtil.service.MainWindowServiceImpl;
using Application = System.Windows.Application;
using MessageBox = System.Windows.MessageBox;

namespace WPF_MVVM_PathSearchUtil.ViewModels
{
    public class FindFormViewModel : Bindable
    {
        private string findWord = string.Empty;
        public string FindWord
        {
            get { return findWord; }
            set { SetProperty(ref findWord, value); }
        }
        public Window CurrentWindow { get; set; }
        public BaseCommand ConfirmButton { get; set; }

        public BaseCommand CancelButton { get;set; }

        public FindFormViewModel(Window window)
        {
            CurrentWindow = window;
            ConfirmButton = new BaseCommand();
            CancelButton = new BaseCommand();
            ConfirmButton.SubScribe(x => { Confirm(); });
            CancelButton.SubScribe(x => { Cancel(); });
        }

        public FindFormViewModel()
        {
        }

        public void Confirm()
        {
            if (FindWord.Length <= 0)
            {
                MessageBox.Show("请输入要检索的文件名。", "提示");
                return;
            }
            // 创建自定义消息对象
            var message = new MyMessage
            {
                Messages = FindWord
            };
            CurrentWindow.Close();
            // 发送消息给所有已注册的接收者
            Messenger.Default.Send(message);
        }

        public void Cancel()
        {
            CurrentWindow.Close();
        }
    }
}
